package org.bonorsoft.modules.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.bonorsoft.modules.user.entity.MobileDepart;

import java.util.List;

public interface MobileDepartMapper extends BaseMapper<MobileDepart> {
    @Select("select * from sys_dept where dept_id IN ( select dept_id from sys_user_depart where user_id = #{userid} )")
    List<MobileDepart> queryUserDeparts(String userid);

    /**
     * 根据ID查询所有子部门
     * @param deptId 部门ID
     * @return 部门列表
     */
    @Select("select * from sys_dept where find_in_set(#{deptId}, ancestors)")
    List<MobileDepart> selectChildrenDeptById(Long deptId);

    /**
     * 修改子元素关系
     *
     * @param depts 子元素
     */
    public void updateDeptChildren(@Param("depts") List<MobileDepart> depts);

    /**
     * 修改所在部门的父级部门状态
     *
     * @param dept 部门
     */
    public void updateDeptStatus(MobileDepart dept);
}
